package com.gmail.dmitryustimov.ms.java7.visitor.mod_actionmap.work.testperf;

import com.gmail.dmitryustimov.ms.java7.patternslib.visitor.actionmap.Visitor;
import com.gmail.dmitryustimov.ms.java7.visitor.mod_actionmap.work.demo.structure1_16_4096_1048576.*;

public class TestPerf1_16_4096_1048576 {

    private static final int NUM_WARM_UP = 3;
    private static final int NUM_TESTS = 10;

    private static final String MESSAGE = "visitor_mod_actionmap, elements structure: 1-16-4096-1048576, took: [";

    public static void main(String[] args) {

        //warm up
        for (int i = 0; i < NUM_WARM_UP; i++) {
            test();
        }

        //tests
        long time = 0;
        for (int j = 0; j < NUM_TESTS; j++) {
            time += test();
        }
        System.out.println("final - " + MESSAGE + time/NUM_TESTS + "ns] ~ [" + (time/NUM_TESTS)/1000000 + "ms]");
    }

    private static long test() {
        Element elementsStructure = new ElementRoot();
        Visitor<Element> visitor = new ConcreteElementVisitor<>();

        long startTime = System.nanoTime();

        visitor.visit(elementsStructure);

        long estimatedTime = System.nanoTime() - startTime;
        System.out.println(MESSAGE + estimatedTime + "ns]");
        return estimatedTime;
    }
}
